import {getServerSession} from "next-auth";
import {authOptions, handler} from "@/app/api/auth/[...nextauth]/route";

import {
    Table,
    TableBody,
    TableCaption,
    TableCell,
    TableFooter,
    TableHead,
    TableHeader,
    TableRow,
} from "@/components/ui/table"

import {
    Pagination,
    PaginationContent,
    PaginationEllipsis,
    PaginationItem,
    PaginationLink,
    PaginationNext,
    PaginationPrevious,
} from "@/components/ui/pagination"

import {Button} from "@/components/ui/button"
import Link from "next/link";

export default async function Home() {
    const session = await getServerSession(authOptions)
    console.log(session)

    const res = await fetch('http://localhost:3000/api/student', {
        method: 'GET',
    })
    const json = await res.json()
    const students = json.students
    console.log(students)

    return (
        <div className={'gap-8 flex flex-col justify-center items-center'}>
            <h1 className={'text-4xl font-bold'}>学生简历分析系统</h1>
            <Table>
                <TableCaption>
                    <Link href={'/student/add'}>
                        学生信息(点击新增)
                    </Link>
                </TableCaption>
                <TableHeader>
                    <TableRow>
                        <TableHead>学生姓名</TableHead>
                        <TableHead>学号</TableHead>
                        <TableHead>班级</TableHead>
                        <TableHead>入学时间</TableHead>
                        <TableHead>操作</TableHead>
                    </TableRow>
                </TableHeader>
                <TableBody>
                    {students.map((s) => (
                        <TableRow key={s.id}>
                            <TableCell>{s.name}</TableCell>
                            <TableCell>{s.studentNumber}</TableCell>
                            <TableCell>{s.class}</TableCell>
                            <TableCell>{s.enrollmentYear.slice(0, 10)}</TableCell>
                            {/*<TableCell>{s.createdAt.slice(0, 10)}</TableCell>*/}
                            {/*<TableCell>{s.updatedAt.slice(0, 10)}</TableCell>*/}
                            <TableCell>
                                <Link href={`/student/delete/${s.id}`}>
                                    <Button variant={"destructive"}>删除</Button>
                                </Link>
                            </TableCell>
                        </TableRow>
                    ))}
                </TableBody>
            </Table>

            {/*分页*/}
            {/*<Pagination>*/}
            {/*    <PaginationContent>*/}
            {/*        <PaginationItem>*/}
            {/*            <PaginationPrevious href="#"/>*/}
            {/*        </PaginationItem>*/}
            {/*        <PaginationItem>*/}
            {/*            <PaginationLink href="#">1</PaginationLink>*/}
            {/*        </PaginationItem>*/}
            {/*        <PaginationItem>*/}
            {/*            <PaginationLink href="#" isActive>*/}
            {/*                2*/}
            {/*            </PaginationLink>*/}
            {/*        </PaginationItem>*/}
            {/*        <PaginationItem>*/}
            {/*            <PaginationLink href="#">3</PaginationLink>*/}
            {/*        </PaginationItem>*/}
            {/*        <PaginationItem>*/}
            {/*            <PaginationEllipsis/>*/}
            {/*        </PaginationItem>*/}
            {/*        <PaginationItem>*/}
            {/*            <PaginationNext href="#"/>*/}
            {/*        </PaginationItem>*/}
            {/*    </PaginationContent>*/}
            {/*</Pagination>*/}
        </div>
    );
}
